home *** CD-ROM | disk | FTP | other *** search
- /* sort1.c: Sort integers with qsort() */
-
- #include <stdio.h>
- #include <stdlib.h>
-
- #define NELEMS 4
-
- static int icomp(const void *, const void *);
-
- main()
- {
- size_t i;
- int some_ints[NELEMS] = {40, 12, 37, 15};
-
- qsort(some_ints,NELEMS,sizeof some_ints[0], icomp);
-
- for (i = 0; i < NELEMS; ++i)
- printf("%d\n",some_ints[i]);
- return 0;
- }
-
- static int icomp(const void *p1, const void *p2)
- {
- int a = * (int *) p1;
- int b = * (int *) p2;
-
- return a - b;
- }
-
- /* Output:
- 12
- 15
- 37
- 40
- */
-